﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Rotempco.BaseClass.Objects.EntityObjects;
using Rotempco.BaseClass;
using Rotempco.Website.Objects;
using Rotempco.BaseClass.Objects.Enums;
using System.Drawing;
using Rotempco.Website.Logic;
using Rotempco.BaseClass.Objects.AttributeStoreObjects;
using Rotempco.Core.Web.Logic;

namespace Rotempco.Website.MasterPages
{
    public partial class Public : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                DataBindControls();
        }


        private void DataBindControls()
        {
            ActiveLanguages activeLanguages = Factory.ActiveLanguages.GetActiveLanguages();

            WebFormFiller.FillRepeater<LanguageTypeEnum>(activeLanguages.ActiveLangaugeList, Repeater_LanguageList);

            Repeater_LanguageList.Items.Cast<RepeaterItem>().ToList().ForEach(item =>
            {
                LinkButton linkButton = item.FindControl("LinkButton_Language") as LinkButton;
                if (linkButton.Text == PublicSessionStore.Instance.LanguageType.ToString())
                {
                    linkButton.Enabled = false;
                    linkButton.CssClass = "selected-language";
                }
            });
        }


        protected void ImageButton_SelectLanguageClick(object sender, EventArgs e)
        {
            LinkButton linkButton = (LinkButton)sender;
            LanguageTypeEnum languageType = (LanguageTypeEnum)Enum.Parse(typeof(LanguageTypeEnum), linkButton.CommandArgument);
            PublicSessionStore.Instance.LanguageType = languageType;
            Response.Redirect(Request.RawUrl);
        }



    }
}